package com.xspace.android.xafcommon.base;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xspace.android.xafcommon.R;

/**
 * Wubj 创建于 2017/3/29 0029.
 */
public class PagerInfoView extends RelativeLayout {

    public ImageView mIvPagerInfo;
    public TextView mTvPagerInfo;
    public Button mBtTvPagerInfoReload;
    public RelativeLayout mRlPagerInfo;
    public RelativeLayout mPagerRootView;


    public PagerInfoView(Context mContext) {
        super(mContext);
        init(mContext, null);
    }

    public PagerInfoView(Context mContext, AttributeSet attrs) {
        super(mContext, attrs);
        init(mContext, attrs);
    }

    public PagerInfoView(Context mContext, AttributeSet attrs, int defStyleAttr) {
        this(mContext, attrs);
    }

    private void init(Context mContext, AttributeSet attrs) {
        LayoutInflater.from(mContext).inflate(R.layout.layout_page_info_view, this, true);
        this.mIvPagerInfo = (ImageView) findViewById(R.id.iv_pager_info);
        this.mTvPagerInfo = (TextView) findViewById(R.id.tv_pager_info);
        this.mBtTvPagerInfoReload = (Button) findViewById(R.id.bt_tv_pager_info_reload);
        this.mRlPagerInfo = (RelativeLayout) findViewById(R.id.rl_pager_info);
        this.mPagerRootView = (RelativeLayout) findViewById(R.id.pager_root_view);
        mBtTvPagerInfoReload.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                PagerInfoView.this.setVisibility(GONE);
                if (onReloadClickListener != null) {
                    onReloadClickListener.onReloadClick(v);
                }
            }
        });
    }

    public void showNetWorkError() {
        this.setVisibility(VISIBLE);
        mIvPagerInfo.setImageResource(R.drawable.net_work_error);
        mTvPagerInfo.setText(R.string.net_work_error);
        mBtTvPagerInfoReload.setVisibility(VISIBLE);
    }

    public void showPageEmpty(String text) {
        this.setVisibility(VISIBLE);
        mIvPagerInfo.setImageResource(R.drawable.icon_common_empty);
        mTvPagerInfo.setText(text);
        mBtTvPagerInfoReload.setVisibility(GONE);
    }

    public void showPageEmpty() {
        this.setVisibility(VISIBLE);
        mIvPagerInfo.setImageResource(R.drawable.icon_common_empty);
        mTvPagerInfo.setText(R.string.content_empty);
        mBtTvPagerInfoReload.setVisibility(GONE);
    }

    public void showPageEmpty(int strResId) {
        this.setVisibility(VISIBLE);
        mIvPagerInfo.setImageResource(R.drawable.icon_common_empty);
        mTvPagerInfo.setText(strResId);
        mBtTvPagerInfoReload.setVisibility(GONE);
    }

    public void hiddenPager() {
        this.setVisibility(GONE);
    }

    public void setPagerInfo(String text) {
        mTvPagerInfo.setText(text);
    }

    public void setPagerInfo(int strResId) {
        mTvPagerInfo.setText(strResId);
    }

    public void setReloadClickListener(OnClickListener onClickListener) {
        mBtTvPagerInfoReload.setOnClickListener(onClickListener);
    }

    private OnReloadClickListener onReloadClickListener;

    public void setOnReloadClickListener(OnReloadClickListener onReloadClickListener) {
        this.onReloadClickListener = onReloadClickListener;
    }

    public interface OnReloadClickListener {
        void onReloadClick(View v);
    }
}
